package babo.cd.physicalexperiment.activity;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

import babo.cd.physicalexperiment.BaseActivity;
import babo.cd.physicalexperiment.R;
import babo.cd.physicalexperiment.adapter.MainViewPageAdapter;
import babo.cd.physicalexperiment.bean.MyDevicesListBean;
import babo.cd.physicalexperiment.bean.ShiyanHistoryListBean;
import babo.cd.physicalexperiment.data.ShiyanHistoryDetailData;
import babo.cd.physicalexperiment.databinding.ActivityHistorydetailBinding;
import babo.cd.physicalexperiment.databinding.ActivityShebeilistmanagerBinding;
import babo.cd.physicalexperiment.fragment.SheBeiFragmentListFragment;
import babo.cd.physicalexperiment.view.RoundAngleImageView;

public class HistoryDetailActivity extends BaseActivity {
    ActivityHistorydetailBinding binding;
    BaseQuickAdapter adapter;
    int type=-1;
    List<ShiyanHistoryDetailData>datas=new ArrayList<>();
    ShiyanHistoryListBean.RecordData item;

    @Override
    protected View bindView() {
        binding=ActivityHistorydetailBinding.inflate(getLayoutInflater());
        return binding.getRoot();
    }

    @Override
    protected void initView() {
        binding.rcv.setLayoutManager(new LinearLayoutManager(context));
        adapter=new BaseQuickAdapter( R.layout.item_shiyanjiludata,datas) {
            @Override
            protected void convert(BaseViewHolder helper, Object item) {
                bindConvert(helper,(ShiyanHistoryDetailData) item);
            }




        };
        binding.rcv.setAdapter(adapter);

    }

    @Override
    public void rightClick() {
        super.rightClick();

    }
    private void bindConvert(BaseViewHolder helper, ShiyanHistoryDetailData item) {
        RoundAngleImageView rvg1=helper.getView(R.id.rvg1);
        RoundAngleImageView rvg2=helper.getView(R.id.rvg2);
        LinearLayout rlc=helper.getView(R.id.rlc);
        TextView txno=helper.getView(R.id.tx_no);
        TextView tx_ctstart=helper.getView(R.id.tx_ctstart);
        TextView tx_jsz_time=helper.getView(R.id.tx_jsz_time);
        TextView tx_wtmiddle=helper.getView(R.id.tx_wtmiddle);
        int psiton=helper.getPosition();
        txno.setText((psiton+1)+"");
        if (psiton%2==1){
            rlc.setBackgroundColor(Color.parseColor("#f5f5f5"));
        }else{
            rlc.setBackgroundColor(Color.parseColor("#ffffff"));
        }


        if (type==1){
            tx_ctstart.setText(""+item.getLargeValue());
            tx_wtmiddle.setText(""+item.getSmallValue());
            tx_jsz_time.setText(""+item.getResultValue());

            if (!TextUtils.isEmpty(item.getLargeImgUrl())){
                Glide.with(context).load(item.getLargeImgUrl()).into(rvg1);
            }
            if (!TextUtils.isEmpty(item.getSmallImgUrl())){
                Glide.with(context).load(item.getSmallImgUrl()).into(rvg2);
            }
        }else{

            if (!TextUtils.isEmpty(item.getStartImgUrl())){
                Glide.with(context).load(item.getStartImgUrl()).into(rvg1);
            }
            if (!TextUtils.isEmpty(item.getMiddleImgUrl())){
                Glide.with(context).load(item.getMiddleImgUrl()).into(rvg2);
            }
            tx_ctstart.setText(""+item.getStartValue());
            tx_wtmiddle.setText(""+item.getMiddleValue());
            tx_jsz_time.setText(""+item.getTimeDifference()+"s");

        }


    }
    @Override
    protected void loadData() {
        item= (ShiyanHistoryListBean.RecordData) getIntent().getSerializableExtra("data");
        type=getIntent().getIntExtra("type",-1);

        if (type==1){
            binding.txImg1title.setText("粗调图");
            binding.txImg12title.setText("微调图");
            binding.txCtstart.setText("粗调值");
            binding.txWtmiddle.setText("微调值");
            binding.txJszTime.setText("计算值");
        }else{
            binding.txImg1title.setText("起点图");
            binding.txImg12title.setText("中点图");
            binding.txCtstart.setText("起点值");
            binding.txWtmiddle.setText("中点值");
            binding.txJszTime.setText("时间差");
        }
        bindData();



    }

    private void bindData() {
        binding.txName.setText("用户:"+item.getUserName());
        binding.txPhone.setText("手机号:"+item.getMobile());
        binding.txSbname.setText("实验设备:"+item.getDeviceName());
        binding.txTime.setText("时间时间:"+item.getCreateTime());
        String zt=item.getExpResult();
        if (zt.equals("2")){
            binding.txStatus.setText("放弃实验");
            binding.txStatus.setTextColor(Color.parseColor("#ff0000"));
        }else{
            binding.txStatus.setText("完成实验");
            binding.txStatus.setTextColor(Color.parseColor("#0133cb"));
        }


        int type=getIntent().getIntExtra("type",-1);
        try {
            String sysj=item.getExpData();
            List<ShiyanHistoryDetailData> list= gson.fromJson(sysj, new TypeToken<List<ShiyanHistoryDetailData>>() {}.getType());

            int size=list.size();
          if (size>0){
              binding.txNodata.setVisibility(View.GONE);
              datas.addAll(list);
              adapter.notifyDataSetChanged();
          }
        }catch (Exception ex){
            binding.txNodata.setVisibility(View.VISIBLE);
        }



    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    public void setListener() {
        super.setListener();
        }
}
